package com.ets.common;

import java.awt.Container;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.JFrame;
import javax.swing.JPanel;

/*******************************************************************************
 The <big><b>Pixels</b></big> class implements the <b>Pixels</b> object
 <br><br>
 @author D.Merkling - 1:33:38 PM - Aug 22, 2011
 <br><br>
 @version 1.2
*******************************************************************************/   
public class Pixels
  {
   private int X;
   private int Y;

   /*******************************************************************************
	This constructor creates a new <b>Pixels</b> object with default values
   *******************************************************************************/   
   public Pixels ()
	 {
	  this.X = 0;
	  this.Y = 0;
	 }

   /*******************************************************************************
	This constructor creates a new <b>Pixels</b> object with attribute values as
	defined by the provided parameters
    <br><br>
	@param horizontal An <b><i>int</i></b> variable
	@param vertical An <b><i>int</i></b> variable
   *******************************************************************************/   
   public Pixels (int horizontal, int vertical)
	 {
	  this.X = horizontal;
	  this.Y = vertical;
	 }

   /*******************************************************************************
	Sets the <b><i>int</i></b> <b>X</b> attribute for the current <b>Pixels</b>
	object
    <br><br>
	@param horizontal An <b><i>int</i></b> variable
   *******************************************************************************/   
   public void setX (int horizontal)
	 {
	  if (horizontal < 0)
	    {
		 this.X = 0;
	    }
	  else
	    {
		 this.X = horizontal;  
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>int</i></b> <b>X</b> attribute from the current
	<b>Pixels</b> object
    <br><br>
	@return X - An <b><i>int</i></b> variable
   *******************************************************************************/   
   public int getX ()
	 {
	  return X;
	 }

   /*******************************************************************************
	Sets the <b><i>int</i></b> <b>Y</b> attribute for the current <b>Pixels</b>
	object
    <br><br>
	@param vertical An <b><i>int</i></b> variable
   *******************************************************************************/   
   public void setY (int vertical)
	 {
	  if (vertical < 0)
	    {
		 this.X = 0;
	    }
	  else
	    {
		 this.X = vertical;  
	    }
	 }

   /*******************************************************************************
	Retrieves the <b><i>int</i></b> <b>Y</b> attribute from the current
	<b>Pixels</b> object
    <br><br>
	@return Y - An <b><i>int</i></b> variable
   *******************************************************************************/   
   public int getY ()
	 {
	  return Y;
	 }
   
   public static Pixels getPixels (Container cont, String type)
     {
	  String tmpType  = type.trim();
	  Pixels pxl      = new Pixels();
	  JFrame tmpFrame = new JFrame();
	  JPanel tmpPanel = new JPanel();
	  if (tmpType.equalsIgnoreCase("Window"))
	    {
	     Toolkit   tk = Toolkit.getDefaultToolkit();
		 Dimension d  = tk.getScreenSize();
		 pxl.X        = d.width;
		 pxl.Y        = d.height;
	    }
	  else if (tmpType.equalsIgnoreCase("Frame"))
	    {
		 tmpFrame = (JFrame) cont;
		 pxl.X    = tmpFrame.getWidth();
		 pxl.Y    = tmpFrame.getHeight();
	    }
	  else if (tmpType.equalsIgnoreCase("Panel"))
	    {
		 tmpPanel = (JPanel) cont; 
		 pxl.X    = tmpPanel.getWidth();
		 pxl.Y    = tmpPanel.getHeight();
	    }
	  return pxl;
     }
  }


